<?php


$title = "Wybierz rasę";
require_once("includes/head.php"); if (!$_GET['ajax']) require_once("includes/head_start.php"); 

/**
* Get the localization for game
*/
require_once("languages/pl/rasa.php");

if (isset ($_GET['race']) && $player -> race2 == '') 
{
    $smarty -> assign(array("Aselect" => A_SELECT,
                            "Aback" => A_BACK));
}

if (isset ($_GET['step']) && $_GET['step'] == 'wybierz' && $player -> race2 == '') 
{
    $smarty -> assign(array("Youselect" => YOU_SELECT,
                            "Click" => CLICK,
                            "Here" => HERE,
                            "Forback" => FOR_BACK));
}

$arrOptionname = array('czlowiek', 'elf', 'krasnolud', 'dragonita', 'ender', 'wolfran', 'eknask', 'virvaenl', 'virvaenw', 'archont', 'bloodlan');
$arrDeityname = array('Człowiek', 'Elf', 'Krasnolud', 'Dragonita', 'Ender', 'Wolfran', 'Eknask', 'Virvaen Lodu', 'Virvaen Wulkanu', 'Archont', 'Bloodlan');

/**
 * Show info about deity
 */
if (isset($_GET['rasa']) && in_array($_GET['rasa'], $arrOptionname))
{
    $arrDeityinfo = array(GOD1_INFO, GOD2_INFO, GOD3_INFO, GOD4_INFO, GOD5_INFO, GOD6_INFO, GOD7_INFO, GOD8_INFO, GOD9_INFO, GOD10_INFO, GOD11_INFO);
    $intKey = array_search($_GET['rasa'], $arrOptionname);
    $smarty -> assign("Godinfo", $arrDeityinfo[$intKey]);
    /**
     * Select deity
     */
    if (isset ($_GET['step']) && $_GET['step'] == 'wybierz') 
    {
	if ($player -> race2 != '') error(YOU_HAVE." (<a href=\"stats.php\">".A_BACK."</a>)");
        $db -> Execute("UPDATE `players` SET `rasa2`='".$arrDeityname[$intKey]."' WHERE `id`=".$player -> id);
        error ("Wybrałeś rasę ".$arrDeityname[$intKey].".");
    }
}


/**
 * Change deity
 */
/*
if (isset($_GET['step']) && $_GET['step'] == 'change')
{
    if ($player -> race2 == '')
    {
        error(ERROR);
    }
	$intCost = $player -> max_energy * 11;
    if (!isset($_GET['step2']))
    {
        $smarty -> assign(array("Change" => CHANGE,
                                "Change2" => CHANGE2,
                                "Ccost" => $intCost,
                                "Ayes" => YES,
                                "Ano" => NO,
                                "Step2" => ''));
    }
        else
    {
    if ($player -> energy < $intCost)
    {
        error('Masz za mało punktów energii!');
    }
        $intKey = array_search($player -> deity, $arrDeityname);
        $db -> Execute("UPDATE `players` SET `energy`=`energy`-".$intCost.", `rasa2` = '' WHERE `id`=".$player -> id);
        $smarty -> assign(array("Step2" => $_GET['step2'],
                                "Youchange" => YOU_CHANGE,
                                "Youmay" => YOU_MAY,
                                "Pdeity" => $arrDeityname2[$intKey],
                                "Aselect2" => A_SELECT2,
                                "Tdeity" => T_DEITY));
    }
}
*/

/**
* Initialization of variables
*/
if (!isset($_GET['rasa'])) 
{
    $_GET['rasa'] = '';
    if (!isset($_GET['step']))
    {
        $smarty -> assign(array("Deityinfo" => DEITY_INFO,
                                "Godname" => $arrDeityname,
                                "Godoption" => $arrOptionname,
								"Ateist" => ATEIST));
    }
}
if (!isset($_GET['step'])) 
{
    $_GET['step'] = '';
}

/**
* Assign variables to template and display page
*/
$smarty -> assign(array("Deity" => $_GET['rasa'], 
                        "Step" => $_GET['step'], 
                        "Pldeity" => $player -> race2));
$smarty -> display ('rasa.tpl');

if (!$_GET['ajax']) require_once("includes/foot.php"); 
?>
